package com.ccs.testdatas;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

import com.ccs.functions.*;

public class OperatingRoom {
	
	public void or(WebDriver driver) throws Exception{
		driver.manage().window().maximize();
		Login in = new Login();
		in.hcs(driver, "specialunit");
		driver.findElement(By.xpath("//a[contains(.,'Nursing Special Units Landing Page')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys("Cocolife");
		driver.findElement(By.xpath("//input[@id='searchMPI']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//a[contains(.,'Outpatient Registration')]")).click();
		
		//OUTPATIENT REGISTRATION
		PatientName name = new PatientName();
		
		double num =  Math.floor((Math.random()*9999)+1);
		String code = String.valueOf(num);
		code = code.replaceAll("\\.","");

		driver.findElement(By.xpath("//input[@id='name.firstName']")).sendKeys("Cocolife"+code);
		String middle = name.names(1);
		driver.findElement(By.xpath("//input[@id='name.middleName']")).sendKeys(middle);
		Select suffix = new Select(driver.findElement(By.xpath("//select[@id='suffix.code']")));
		suffix.selectByVisibleText("JR");
		driver.findElement(By.xpath("//input[@id='birthDate']")).sendKeys("01/01/1995");
		driver.findElement(By.xpath("//input[@id='gender1']")).click();
		driver.findElement(By.xpath("//input[@id='presentAddrNumStreet']")).sendKeys("E. Rodriquez");
		driver.findElement(By.xpath("//input[@id='presentAddrBldg']")).sendKeys("St. Luke's");
		Select city = new Select(driver.findElement(By.xpath("//select[@id='presentAddrCitySelect']")));
		city.selectByVisibleText("MANILA CITY");
		driver.findElement(By.xpath("//input[@id='presentAddrProvince']")).sendKeys("Metro Manila");
		driver.findElement(By.xpath("//input[@id='presentAddrPostalCode']")).sendKeys("1800");
		
		//SUBMIT FORM
		driver.findElement(By.xpath("//div[@id='controls']/input[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//ADMIT PATIENT TO OPERATING ROOM
		AdmissionHCS hcs = new AdmissionHCS();
		hcs.admit(driver, "special");
		
		String pin = driver.findElement(By.xpath("//div[@id='main']/div[6]/div[1]/div")).getText();
		pin = pin.replaceAll(" ", "");
		System.out.println("PIN No of Patient is: "+pin);
		
		hcs.save_admission(driver, "special");
		
		//GOTO OCCUPANCY LIST
		driver.findElement(By.xpath("//a[contains(.,'Occupancy List')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

		//ORDER PAGE
		String orderForm = driver.getWindowHandle();
		driver.switchTo().window(orderForm);
		Select occupancy = new Select(driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[9]/select")));
		occupancy.selectByVisibleText("Order Page");
		driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[10]/input")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='orderType1']")).click();
		driver.findElement(By.xpath("//input[@id='oif_entity_finder_key']")).sendKeys("044006788");
		driver.findElement(By.xpath("//div[@id='serviceSearch']/div[4]/input[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='quantity']")).clear();
		driver.findElement(By.xpath("//input[@id='quantity']")).sendKeys("10");
		driver.findElement(By.xpath("//input[@value='Add']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@value='Submit']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='drugOrderCartDetailCheckAll']")).click();
		driver.findElement(By.xpath("//input[@id='validate']")).click();
		driver.findElement(By.xpath("//input[@value='OK']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//GO BACK TO OCCUPANCY LIST
		driver.findElement(By.xpath("//a[contains(.,'Occupancy List')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//PROCESS CLINICAL DISCHARGE AND INSTRUCTION
		Nursing nurse = new Nursing();
		nurse.discharge(driver, pin, "special");
		
		//GO BACK TO OCCUPANCY LIST
		driver.findElement(By.xpath("//a[contains(.,'Occupancy List')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//PROCESS CLINICAL DISCHARGE FOR PF
		nurse.pf(driver, pin, "special");
		Logout out = new Logout();
		out.hcs(driver);
		
		//PROCESS BILLING DISCHARGE
		in.hcs(driver, "billing");
		Billing bill = new Billing();
		bill.goto_discharge_home(driver, pin);
		bill.select_discharge(driver, "regular");
		bill.update_guarantor(driver, pin);
		bill.goto_discharge_home(driver, pin);
		bill.regular_discharge(driver, "hmo");
		
	}
	
	
}
